<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    
</body>
<script>
    // 电子厂：手机（打电话，玩游戏），电脑（玩游戏），一套测试模块：打电话，玩游戏

    function CreatePhone(){
        this.name = "手机"
        this.call = function(){
            console.log("打电话")
        }
        this.game = function(){
            console.log("玩游戏")
        }
    }
    function CreateComputer(){
        this.name = "电脑"
        this.game = function(){
            console.log("玩游戏")
        }
    }


    function test(obj){
        obj.call();
        obj.game();
    }

    const p = new CreatePhone()
    const c = new CreateComputer()

    function Adapter(obj){
        if(!obj.call){
            obj.call = function(){
                console.log("这是" + obj.name + "没有打电话功能")
            }
        }
        return obj;
    }

    test(p);
    test( Adapter(c) );

    console.log(p)
    console.log(c)

</script>
</html>